package com.taoge.p4.common.utils;

import java.util.Date;

public class TokenUtil {

    public static String generateToken() {
        return generateToken(SnowFlake.nextId());
    }

    public static String generateToken(Long userId) {
        Date loginDate = new Date();
        String token = AESUtil.AESEncode(userId + "," + loginDate);
        return token;
    }

    public static Long parseToken(String token) {
        if (null == token) {
            return null;
        }
        String s = AESUtil.AESDecode(token);
        String[] split = s.split(",");
        return Long.parseLong(split[0]);
    }

//    public static void main(String[] args) {
//        Long l = parseToken("iyOLTXHooGpvShIUx5KZPeSp0zNYexPM0SN/P1c2DyI=");
//        System.out.println(l);
//    }
}
